package com.fjj.cs.vo.request;

import com.fjj.cs.enums.ErrorCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * description 请求结果信息类
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultVo<T> {


	private String code;
	private String msg;
	private T data;

	public ResultVo(ErrorCode codeEnum, String msg) {
		this.code = codeEnum.getCode();
		this.msg = msg;
	}

	public ResultVo(ErrorCode codeEnum) {
		this.code = codeEnum.getCode();
		this.msg = codeEnum.getMsg();
	}

	public ResultVo(ErrorCode codeEnum, T data) {
		this.code = codeEnum.getCode();
		this.msg = codeEnum.getMsg();
		this.data = data;
	}

	public ResultVo(ErrorCode codeEnum, String msg, T data) {
		this.code = codeEnum.getCode();
		this.msg = msg;
		this.data = data;
	}

	public ResultVo(String code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public static <T> ResultVo<T> success() {
		return new ResultVo<>(ErrorCode.SUCCESS);
	}

	public static <T> ResultVo<T> success(T t) {
		return new ResultVo<>(ErrorCode.SUCCESS, t);
	}

	public static <T> ResultVo<T> success(String msg, T t) {
		return new ResultVo<>(ErrorCode.SUCCESS, msg, t);
	}

	public static <T> ResultVo<T> success(ErrorCode codeEnum, T t) {
		return new ResultVo<>(codeEnum, t);
	}

	public static <T> ResultVo<T> error(String msg) {
		return new ResultVo<>(ErrorCode.ERROR, msg);
	}

	public static <T> ResultVo<T> error(ErrorCode codeEnum, String msg) {
		return new ResultVo<>(codeEnum, msg);
	}

	public static <T> ResultVo<T> error(ErrorCode codeEnum) {
		return new ResultVo<>(codeEnum);
	}

	public static <T> ResultVo<T> error(String msg, T t) {
		return new ResultVo<>(ErrorCode.ERROR, msg, t);
	}

	public static <T> ResultVo<T> error(String code, String msg) {
		return new ResultVo<>(code, msg);
	}
	
	public static <T> ResultVo<T> error(String code, String msg, T data) {
		return new ResultVo<>(code, msg, data);
	}

	public Boolean isSuccess() {
		if (ErrorCode.SUCCESS.getCode().equalsIgnoreCase(this.code)) {
			return true;
		} else {
			return false;
		}
	}

}
